#include <iostream>
#include <string>

class Book {
private:
    std::string title;  // 书名
    std::string author; // 作者
    int stock;          // 库存数量，外部不可直接访问

public:
    Book(const std::string& title, const std::string& author, int stock)
        : title(title), author(author), stock(stock) {}

   void display() const {
        std::cout << "Title: " << title << ", Author: " << author << std::endl;
    }

    // 提供公共接口检查库存是否充足
    bool isAvailable() const {
        return stock > 0;
    }

    // 处理借书，只在库存充足时成功
    bool borrowBook() {
        if (isAvailable()) {
            --stock;
            std::cout << title << " borrowed. Remaining Stock: " << stock << std::endl;
            return true;
        } else {
            std::cout << title << " is currently out of stock." << std::endl;
            return false;
        }
    }


    // 处理还书，库存增加
    void returnBook() {
        ++stock;
        std::cout << title << " returned. New Stock: " << stock << std::endl;
    }
};

int main() {
    Book myBook("The C++ Programming Language", "Bjarne Stroustrup", 3);

    myBook.display(); // 显示书籍信息
    myBook.borrowBook(); // 借出一本书
    myBook.borrowBook(); // 再借出一本
    myBook.returnBook(); // 归还一本书

    return 0;
}
